package com.hgz.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

public class ReadAndWriteFile {
	
    public static final String LINE_SEPARATOR_WINDOWS = "\r\n";
	public static void javaWriteFile(String path,String writeCotent) throws IOException
	{
		File file=new File(path);
		if(!file.exists())
			file.createNewFile();
		FileOutputStream out;
		out = new FileOutputStream(file,true);
		String cotent =  writeCotent;
		byte[] nextline = LINE_SEPARATOR_WINDOWS.getBytes();
		out.write(cotent.getBytes("utf-8"));
		out.write(nextline);
		out.close();

	}

	//java读取文件
	public static String javaReaderFile(String path) throws IOException
	{  
		File file=new File(path);
		if(!file.exists()||file.isDirectory())
			throw new FileNotFoundException();
		BufferedReader br=new BufferedReader(new FileReader(file));
		String temp=null;
		StringBuffer sb=new StringBuffer();
		temp=br.readLine();
		while(temp!=null){
			sb.append(temp+" ");
			temp=br.readLine();
			System.out.println("读取>>>>>>"+temp);
		}
		return sb.toString();
	}

}
